package com.blockmeta.bbs.minemodule.activity;

import com.google.android.material.tabs.TabLayout;
import androidx.fragment.app.Fragment;
import androidx.viewpager.widget.ViewPager;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.LinearLayout;

import com.blockmeta.bbs.baselibrary.base.adapter.BaseTabViewPagerAdapter;
import com.blockmeta.bbs.businesslibrary.base.BaseActivity;
import com.blockmeta.bbs.minemodule.R;
import com.blockmeta.bbs.minemodule.R2;
import com.blockmeta.bbs.minemodule.fragment.FeedBackFragment;
import com.blockmeta.bbs.minemodule.fragment.FeedBackHistoryFragment;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

import butterknife.BindView;
import butterknife.OnClick;

public class FeedbackActivity extends BaseActivity implements TabLayout.OnTabSelectedListener {
    @BindView(R2.id.tab_switch)
    TabLayout mTabSwitch;
    @BindView(R2.id.vp_container)
    ViewPager mVpContainer;
    @BindView(R2.id.send_send)
    LinearLayout mSendSend;
    private List<Fragment> mFragments = new ArrayList<>(2);

    @Override
    protected boolean showTitle() {
        return false;
    }

    @Override
    public View setView() {
        return LayoutInflater.from(this).inflate(R.layout.activity_feedback, null);
    }

    @Override
    protected void initialize() {
        super.initialize();
        mFragments.add(new FeedBackFragment());
        mFragments.add(new FeedBackHistoryFragment());
        String[] titles = {"提交反馈", "历史反馈"};
        mVpContainer.setAdapter(new BaseTabViewPagerAdapter(getSupportFragmentManager(), mFragments, Arrays.asList(titles)));
        mTabSwitch.setupWithViewPager(mVpContainer);
        mTabSwitch.addOnTabSelectedListener(this);
    }

    @OnClick({R2.id.send_cancle, R2.id.send_send})
    public void onViewClicked(View view) {
        int i = view.getId();
        if (i == R.id.send_cancle) {
            finish();

        } else if (i == R.id.send_send) {
            ((FeedBackFragment) mFragments.get(0)).postTheFeed();

        }
    }

    @Override
    public void onTabSelected(TabLayout.Tab tab) {
        if (tab.getPosition() == 0) {
            mSendSend.setVisibility(View.VISIBLE);
        }else {
            mSendSend.setVisibility(View.GONE);
        }
    }

    @Override
    public void onTabUnselected(TabLayout.Tab tab) {

    }

    @Override
    public void onTabReselected(TabLayout.Tab tab) {

    }
}
